//
//  NewRecords.m
//  haolaDoc
//
//  Created by chen on 2017/5/12.
//  Copyright © 2017年 deyi. All rights reserved.
//

#import "NewRecords.h"
#import "Consultation.h"
@interface NewRecords ()<UITextFieldDelegate>

@end

@implementation NewRecords

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _createRecordsScrollview.contentSize = CGSizeMake(0,self.view.frame.size.height);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//字典转为 json 格式
-(NSString *)convertToJsonData:(NSDictionary *)dict

{
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        
        NSLog(@"%@",error);
        
    }else{
        
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        
    }
    
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
    
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"returnConsultation"]){
        NSString *nf=_nameField.text;
        NSString *sf=_sexField.text;
        NSString *af=_ageField.text;
        NSString *tf=_timeField.text;
        NSString *ccf=_chiefcomplaintField.text;
        NSString *nif=_nowillField.text;
        NSString *lif=_lastillField.text;
        NSString *pef=_physicalexaminationField.text;
        NSString *df=_diagnosedField.text;
        NSString *trf=_treatmentField.text;
        
        NSDictionary *medicalrecorddic = [[NSDictionary alloc] initWithObjectsAndKeys:nf,@"patientName",sf,@"patientSex",af,@"patientAge",tf,@"EMRDate",ccf,@"chiefComplaint",nif,@"presentIll",lif,@"pastHistory",pef,@"healthExam",df,@"xgc",trf,@"handle", nil ];
        _createRecords=[self convertToJsonData:medicalrecorddic];
        NSLog(@"这是输出%@",_createRecords);
        Consultation *newconsultationview=segue.destinationViewController;
        newconsultationview.sendRecords=_createRecords;
    }
    
    
}



- (IBAction)finishCreate:(id)sender {
     [self performSegueWithIdentifier:@"returnConsultation" sender:self];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
